import java.util.concurrent.CountDownLatch;

public class demo4 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(20);

        for (int i = 0; i < 20; i++) {
            int finalI = i;
            Thread thread = new Thread(() -> {
                System.out.println(finalI);
                latch.countDown();
            });
            thread.start();
        }

        latch.await(); // 等待所有子线程执行完毕

        System.out.println("ok,执行完成");
    }


}
